﻿using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DSParaView
{

    public partial class CtrlSortItem : UserControl
    {
        public static CtrlSortItemModel DataClone;
        public CtrlSortItem()
        {
            InitializeComponent();
        }

        private void BtnClick_FastSet(object sender, RoutedEventArgs e)
        {
            var dx = this.DataContext as CtrlSortItemModel;
            if (dx == null)
            {
                return;

            }
            double nowVal = dx.StartVal;
            foreach (var item in dx.ListLevelData)
            {
                item.MinVal = nowVal; nowVal += dx.AddIntervel;
                item.MaxVal = nowVal;
            }
        }

        private void BtnClick_Copy(object sender, RoutedEventArgs e)
        {
            var dx = this.DataContext as CtrlSortItemModel;
            if (dx == null)
            {
                return;
            }
            DataClone = dx;
            MessageBox.Show("已复制");
        }

        private void BtnClick_Paste(object sender, RoutedEventArgs e)
        {
            var dx = this.DataContext as CtrlSortItemModel;
            if (dx == null)
            {
                return;
            }
            if (DataClone != null)
            {
                for (int i = 0; i < DataClone.ListLevelData.Count&& i < dx.ListLevelData.Count; i++)
                {
                    dx.ListLevelData[i].MinVal = DataClone.ListLevelData[i].MinVal;
                    dx.ListLevelData[i].MaxVal = DataClone.ListLevelData[i].MaxVal;
                }
                MessageBox.Show("已粘贴");
            }
        }
    }

    public class CtrlSortItemModel : ViewModelBase
    {
        private bool _IsUse;
        public bool IsUse { get => _IsUse; set => Set("IsUse", ref _IsUse, value); }

        private string _Title;

        public string Title
        {
            get => _Title; set
            {
                Set("Title", ref _Title, value);
                foreach (var item in ListLevelData)
                {
                    item.Flag = $"≤{value}<";
                }
            }
        }

        private ObservableCollection<CtrlLevelItemModel> _ListLevelData = new ObservableCollection<CtrlLevelItemModel>();
        public ObservableCollection<CtrlLevelItemModel> ListLevelData { get { return _ListLevelData; } set { Set("ListLevelData", ref _ListLevelData, value); } }

        private double _StartVal;
        public double StartVal { get => _StartVal; set => Set("StartVal", ref _StartVal, value); }


        private double _AddIntervel = 10;
        public double AddIntervel { get => _AddIntervel; set => Set("AddIntervel", ref _AddIntervel, value); }





    }

    public class CtrlLevelItemModel : ViewModelBase
    {
        private double _MinVal;
        public double MinVal { get => _MinVal; set => Set("MinVal", ref _MinVal, value); }
        private double _MaxVal;
        public double MaxVal { get => _MaxVal; set => Set("MaxVal", ref _MaxVal, value); }

        private int _AtLevel;
        public int AtLevel { get => _AtLevel; set => Set("AtLevel", ref _AtLevel, value); }

        private string _Flag;
        public string Flag { get => _Flag; set => Set("Flag", ref _Flag, value); }
    }
}